<?php

/**
 * url管理logic
 */

namespace Member\Logic;

class UrlsLogic extends BaseLogic {
    
	protected $_auto = array(
	    array('uid',UID),
		array('createtime','time',1,'function'),
	);
	
	/**
	 * 获取全部的普通的url
	 */
	public function allLists($map = array('uid'=>UID),$field = array('id','name','url')){
	
		
		$data = $this->where($map)->field($field)->select();
	
		return $data;
	}
	
	/**
	 * (non-PHPdoc)
	 * @see \Member\Logic\BaseLogic::update()
	 */
	public function update($id = 0){
		/* 获取文章数据 */
		$data = $this->create();
		
		$data['uid'] = UID;
		
		//自动在前面加上http://前缀
		$data['url'] = trim($data['url']);
		
		if((substr($data['url'], 0,7) != 'http://') && (substr($data['url'], 0,8) != 'https://')){
			$data['url'] = 'http://'.$data['url'];
		}
		
		if($data === false){
			return false;
		}
		
		/* 添加或更新数据 */
		if(empty($data['id'])){//新增数据
			$data['id'] = $id;
			$id = $this->add($data);
			if(!$id){
				$this->error = '新增详细内容失败！';
				return false;
			}
		} else { //更新数据
			$status = $this->save($data);
			if(false === $status){
				$this->error = '更新详细内容失败！';
				return false;
			}
		}
		
		return true;
	}
	
	/**
	 * (non-PHPdoc)
	 * @see \Member\Logic\BaseLogic::autoSave()
	 */
	public function autoSave($id = 0){
		 
	}
}